<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style>
body {
  font-family: Helvetica, arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  padding-top: 10px;
  padding-bottom: 10px;
  background-color: white;
  padding: 30px; }

body > *:first-child {
  margin-top: 0 !important; }
body > *:last-child {
  margin-bottom: 0 !important; }

a {
  color: #4183C4; }
a.absent {
  color: #cc0000; }
a.anchor {
  display: block;
  padding-left: 30px;
  margin-left: -30px;
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0; }

h1, h2, h3, h4, h5, h6 {
  margin: 20px 0 10px;
  padding: 0;
  font-weight: bold;
  -webkit-font-smoothing: antialiased;
  cursor: text;
  position: relative; }

h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
  background: url() no-repeat 10px center;
  text-decoration: none; }

h1 tt, h1 code {
  font-size: inherit; }

h2 tt, h2 code {
  font-size: inherit; }

h3 tt, h3 code {
  font-size: inherit; }

h4 tt, h4 code {
  font-size: inherit; }

h5 tt, h5 code {
  font-size: inherit; }

h6 tt, h6 code {
  font-size: inherit; }

h1 {
  font-size: 28px;
  color: black; }

h2 {
  font-size: 24px;
  border-bottom: 1px solid #cccccc;
  color: black; }

h3 {
  font-size: 18px; }

h4 {
  font-size: 16px; }

h5 {
  font-size: 14px; }

h6 {
  color: #777777;
  font-size: 14px; }

p, blockquote, ul, ol, dl, li, table, pre {
  margin: 15px 0; }

hr {
  background: transparent url() repeat-x 0 0;
  border: 0 none;
  color: #cccccc;
  height: 4px;
  padding: 0;
}

body > h2:first-child {
  margin-top: 0;
  padding-top: 0; }
body > h1:first-child {
  margin-top: 0;
  padding-top: 0; }
  body > h1:first-child + h2 {
    margin-top: 0;
    padding-top: 0; }
body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
  margin-top: 0;
  padding-top: 0; }

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
  margin-top: 0;
  padding-top: 0; }

h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
  margin-top: 0; }

li p.first {
  display: inline-block; }
li {
  margin: 0; }
ul, ol {
  padding-left: 30px; }

ul :first-child, ol :first-child {
  margin-top: 0; }

dl {
  padding: 0; }
  dl dt {
    font-size: 14px;
    font-weight: bold;
    font-style: italic;
    padding: 0;
    margin: 15px 0 5px; }
    dl dt:first-child {
      padding: 0; }
    dl dt > :first-child {
      margin-top: 0; }
    dl dt > :last-child {
      margin-bottom: 0; }
  dl dd {
    margin: 0 0 15px;
    padding: 0 15px; }
    dl dd > :first-child {
      margin-top: 0; }
    dl dd > :last-child {
      margin-bottom: 0; }

blockquote {
  border-left: 4px solid #dddddd;
  padding: 0 15px;
  color: #777777; }
  blockquote > :first-child {
    margin-top: 0; }
  blockquote > :last-child {
    margin-bottom: 0; }

table {
  padding: 0;border-collapse: collapse; }
  table tr {
    border-top: 1px solid #cccccc;
    background-color: white;
    margin: 0;
    padding: 0; }
    table tr:nth-child(2n) {
      background-color: #f8f8f8; }
    table tr th {
      font-weight: bold;
      border: 1px solid #cccccc;
      margin: 0;
      padding: 6px 13px; }
    table tr td {
      border: 1px solid #cccccc;
      margin: 0;
      padding: 6px 13px; }
    table tr th :first-child, table tr td :first-child {
      margin-top: 0; }
    table tr th :last-child, table tr td :last-child {
      margin-bottom: 0; }

img {
  max-width: 100%; }

span.frame {
  display: block;
  overflow: hidden; }
  span.frame > span {
    border: 1px solid #dddddd;
    display: block;
    float: left;
    overflow: hidden;
    margin: 13px 0 0;
    padding: 7px;
    width: auto; }
  span.frame span img {
    display: block;
    float: left; }
  span.frame span span {
    clear: both;
    color: #333333;
    display: block;
    padding: 5px 0 0; }
span.align-center {
  display: block;
  overflow: hidden;
  clear: both; }
  span.align-center > span {
    display: block;
    overflow: hidden;
    margin: 13px auto 0;
    text-align: center; }
  span.align-center span img {
    margin: 0 auto;
    text-align: center; }
span.align-right {
  display: block;
  overflow: hidden;
  clear: both; }
  span.align-right > span {
    display: block;
    overflow: hidden;
    margin: 13px 0 0;
    text-align: right; }
  span.align-right span img {
    margin: 0;
    text-align: right; }
span.float-left {
  display: block;
  margin-right: 13px;
  overflow: hidden;
  float: left; }
  span.float-left span {
    margin: 13px 0 0; }
span.float-right {
  display: block;
  margin-left: 13px;
  overflow: hidden;
  float: right; }
  span.float-right > span {
    display: block;
    overflow: hidden;
    margin: 13px auto 0;
    text-align: right; }

code, tt {
  margin: 0 2px;
  padding: 0 5px;
  white-space: nowrap;
  border: 1px solid #eaeaea;
  background-color: #f8f8f8;
  border-radius: 3px; }

pre code {
  margin: 0;
  padding: 0;
  white-space: pre;
  border: none;
  background: transparent; }

.highlight pre {
  background-color: #f8f8f8;
  border: 1px solid #cccccc;
  font-size: 13px;
  line-height: 19px;
  overflow: auto;
  padding: 6px 10px;
  border-radius: 3px; }

pre {
  background-color: #f8f8f8;
  border: 1px solid #cccccc;
  font-size: 13px;
  line-height: 19px;
  overflow: auto;
  padding: 6px 10px;
  border-radius: 3px; }
  pre code, pre tt {
    background-color: transparent;
    border: none; }

sup {
    font-size: 0.83em;
    vertical-align: super;
    line-height: 0;
}
* {
	-webkit-print-color-adjust: exact;
}
@media screen and (min-width: 914px) {
    body {
        width: 854px;
        margin:0 auto;
    }
}
@media print {
	table, pre {
		page-break-inside: avoid;
	}
	pre {
		word-wrap: break-word;
	}
}
</style>
<title>助手函数</title>

</head>
<body>
<h1>助手函数</h1>

<ul>
<li><a href="#arrays">数组</a></li>
<li><a href="#paths">路径</a></li>
<li><a href="#strings">字符串</a></li>
<li><a href="#urls">URLs</a></li>
<li><a href="#miscellaneous">杂项</a></li>
</ul>


<p><a name="arrays"></a></p>

<h2>数组</h2>

<h3>array_add</h3>

<p><code>array_add</code> 函数添加一个键/值对到数组如果给定的键在数组中不存在。</p>

<pre><code>$array = array('foo' =&gt; 'bar');

$array = array_add($array, 'key', 'value');
</code></pre>

<h3>array_divide</h3>

<p>The <code>array_divide</code> 函数返回两个数组，一个包含这个数组中所有的键，另一个包含这个数组中所有的值。</p>

<pre><code>$array = array('foo' =&gt; 'bar');

list($keys, $values) = array_divide($array);
</code></pre>

<h3>array_dot</h3>

<p><code>array_dot</code> 函数使用点符号表示层次把一个多维数组转为一个一维数组。</p>

<pre><code>$array = array('foo' =&gt; array('bar' =&gt; 'baz'));

$array = array_dot($array);

// array('foo.bar' =&gt; 'baz');
</code></pre>

<h3>array_except</h3>

<p><code>array_except</code> 函数从数组中删除给定的键/值对。</p>

<pre><code>$array = array_except($array, array('keys', 'to', 'remove'));
</code></pre>

<h3>array_fetch</h3>

<p><code>array_fetch</code> 函数返回一个扁平的数组包含所选的嵌套元素。</p>

<pre><code>$array = array(array('name' =&gt; 'Taylor'), array('name' =&gt; 'Dayle'));

var_dump(array_fetch($array, 'name'));

// array('Taylor', 'Dayle');
</code></pre>

<h3>array_first</h3>

<p><code>array_first</code> 函数根据给定的布尔测试返回数组的第一个元素。</p>

<pre><code>$array = array(100, 200, 300);

$value = array_first($array, function($key, $value)
{
    return $value &gt;= 150;
});
</code></pre>

<p>一个默认值可以通过第三个参数被传递：</p>

<pre><code>$value = array_first($array, $callback, $default);
</code></pre>

<h3>array_flatten</h3>

<p><code>array_flatten</code> 函数将扁平一个多维数组到一个一维数组。</p>

<pre><code>$array = array('name' =&gt; 'Joe', 'languages' =&gt; array('PHP', 'Ruby'));

$array = array_flatten($array);

// array('Joe', 'PHP', 'Ruby');
</code></pre>

<h3>array_forget</h3>

<p><code>array_forget</code> 函数将从使用点符号从嵌套的数组删除给定的键/值对。</p>

<pre><code>$array = array('names' =&gt; array('joe' =&gt; array('programmer')));

$array = array_forget($array, 'names.joe');
</code></pre>

<h3>array_get</h3>

<p><code>array_get</code> 函数将使用点符号从嵌套的数组获取值。</p>

<pre><code>$array = array('names' =&gt; array('joe' =&gt; array('programmer')));

$value = array_get($array, 'names.joe');
</code></pre>

<h3>array_only</h3>

<p><code>array_only</code> 函数将从数组中返回指定的键/值对。</p>

<pre><code>$array = array('name' =&gt; 'Joe', 'age' =&gt; 27, 'votes' =&gt; 1);

$array = array_only($array, array('name', 'votes'));
</code></pre>

<h3>array_pluck</h3>

<p><code>array_pluck</code> 函数将从数组的键/值对中导出一个列表。</p>

<pre><code>$array = array(array('name' =&gt; 'Taylor'), array('name' =&gt; 'Dayle'));

$array = array_pluck($array, 'name');

// array('Taylor', 'Dayle');
</code></pre>

<h3>array_pull</h3>

<p><code>array_pull</code> 函数将从数组中返回给定的键/值对，并删除它。</p>

<pre><code>$array = array('name' =&gt; 'Taylor', 'age' =&gt; 27);

$name = array_pull($array, 'name');
</code></pre>

<h3>array_set</h3>

<p><code>array_set</code> 函数使用点符号在深层嵌套的数组中设置一个值。</p>

<pre><code>$array = array('names' =&gt; array('programmer' =&gt; 'Joe'));

array_set($array, 'names.editor', 'Taylor');
</code></pre>

<h3>array_sort</h3>

<p><code>array_sort</code> 函数通过给定的闭包函数对数组排序。</p>

<pre><code>$array = array(
    array('name' =&gt; 'Jill'),
    array('name' =&gt; 'Barry'),
);

$array = array_values(array_sort($array, function($value)
{
    return $value['name'];
}));
</code></pre>

<h3>head</h3>

<p>返回数组的第一个元素。在 PHP 5.3.x 的链式方法中有用。</p>

<pre><code>$first = head($this-&gt;returnsArray('foo'));
</code></pre>

<h3>last</h3>

<p>返回数组的最后一个元素。在链式方法中有用。</p>

<pre><code>$last = last($this-&gt;returnsArray('foo'));
</code></pre>

<p><a name="paths"></a></p>

<h2>路径</h2>

<h3>app_path</h3>

<p>返回 <code>application</code> 目录的完整路径。</p>

<h3>base_path</h3>

<p>返回应用安装主目录的完整路径。</p>

<h3>public_path</h3>

<p>返回 <code>public</code> 目录的完整路径。</p>

<h3>storage_path</h3>

<p>返回 <code>application/storage</code> 目录的完整路径。</p>

<p><a name="strings"></a></p>

<h2>字符串</h2>

<h3>camel_case</h3>

<p>使用 <code>camelCase</code> 方法转换一个给定字符串。</p>

<pre><code>$camel = camel_case('foo_bar');

// fooBar
</code></pre>

<h3>class_basename</h3>

<p>获取给定类的类名，除去任何名字空间。</p>

<pre><code>$class = class_basename('Foo\Bar\Baz');

// Baz
</code></pre>

<h3>e</h3>

<p>对给定字符串运行 <code>htmlentites</code>，支持UTF-8。</p>

<pre><code>$entities = e('&lt;html&gt;foo&lt;/html&gt;');
</code></pre>

<h3>ends_with</h3>

<p>检查某字符串是否以给定的字符串结尾。</p>

<pre><code>$value = ends_with('This is my name', 'name');
</code></pre>

<h3>snake_case</h3>

<p>使用 <code>snake_case</code> 方法转换一个给定的字符串。</p>

<pre><code>$snake = snake_case('fooBar');

// foo_bar
</code></pre>

<h3>starts_with</h3>

<p>检查某字符串是否以给定的字符串开头。</p>

<pre><code>$value = starts_with('This is my name', 'This');
</code></pre>

<h3>str_contains</h3>

<p>检查某字符串是否包含给定的字符串。</p>

<pre><code>$value = str_contains('This is my name', 'my');
</code></pre>

<h3>str_finish</h3>

<p>添加一个字符串实例到某字符串，删除任何这个字符串已存在的实例。</p>

<pre><code>$string = str_finish('this/string', '/');

// this/string/
</code></pre>

<h3>str_is</h3>

<p>确定给定的字符串是否匹配给定的模式表达式。可使用星号作为通配符。</p>

<pre><code>$value = str_is('foo*', 'foobar');
</code></pre>

<h3>str_plural</h3>

<p>将字符串转换成它的复数形式（只支持英文）。</p>

<pre><code>$plural = str_plural('car');
</code></pre>

<h3>str_random</h3>

<p>生成一个给定长度的随机字符串。</p>

<pre><code>$string = str_random(40);
</code></pre>

<h3>str_singular</h3>

<p>将字符串转换成它的单数形式（只支持英文）。</p>

<pre><code>$singular = str_singular('cars');
</code></pre>

<h3>studly_case</h3>

<p>使用 <code>StudlyCase</code> 方法转换一个给定的字符串。</p>

<pre><code>$value = studly_case('foo_bar');

// FooBar
</code></pre>

<h3>trans</h3>

<p>翻译一个语言行，作为 <code>Lang::get</code> 的快捷方式。</p>

<pre><code>$value = trans('validation.required'):
</code></pre>

<h3>trans_choice</h3>

<p>使用反射翻译一个语言行，作为 <code>Lang::choice</code> 的快捷方式。</p>

<pre><code>$value = trans_choice('foo.bar', $count);
</code></pre>

<p><a name="urls"></a></p>

<h2>URLs</h2>

<h3>action</h3>

<p>对给定的控制器动作生成 URL。</p>

<pre><code>$url = action('HomeController@getIndex', $params);
</code></pre>

<h3>asset</h3>

<p>对一个资源生成 URL。</p>

<pre><code>$url = asset('img/photo.jpg');
</code></pre>

<h3>link_to</h3>

<p>对一个 HTML 链接生成 URL。</p>

<pre><code>echo link_to('foo/bar', $title, $attributes = array(), $secure = null);
</code></pre>

<h3>link_to_asset</h3>

<p>对给定的资源生成一个 HTML 链接。</p>

<pre><code>echo link_to_asset('foo/bar.zip', $title, $attributes = array(), $secure = null);
</code></pre>

<h3>link_to_route</h3>

<p>对给定的路由生成一个 HTML 链接。</p>

<pre><code>echo link_to_route('route.name', $title, $parameters = array(), $attributes = array());
</code></pre>

<h3>link_to_action</h3>

<p>对给定的控制器动作生成一个 HTML 链接。</p>

<pre><code>echo link_to_action('HomeController@getIndex', $title, $parameters = array(), $attributes = array());
</code></pre>

<h3>secure_asset</h3>

<p>使用 HTTPS 对给定的资源生成一个 HTML 链接。</p>

<pre><code>echo secure_asset('foo/bar.zip', $title, $attributes = array());
</code></pre>

<h3>secure_url</h3>

<p>使用 HTTPS 对给定的路径生成完整的 URL。</p>

<pre><code>echo secure_url('foo/bar', $parameters = array());
</code></pre>

<h3>url</h3>

<p>根据给定的路径生成完整的 URL。</p>

<pre><code>echo url('foo/bar', $parameters = array(), $secure = null);
</code></pre>

<p><a name="miscellaneous"></a></p>

<h2>杂项</h2>

<h3>csrf_token</h3>

<p>获取当前 CSRF 令牌的值。</p>

<pre><code>$token = csrf_token();
</code></pre>

<h3>dd</h3>

<p>打印指定变量的值并且停止运行脚本。</p>

<pre><code>dd($value);
</code></pre>

<h3>value</h3>

<p>如果指定的值是一个闭包，返回闭包函数所返回的值，否则直接返回这个值。</p>

<pre><code>$value = value(function() { return 'bar'; });
</code></pre>

<h3>with</h3>

<p>返回指定的对象。对 PHP 5.3.x 中的链式函数调用很有用。</p>

<pre><code>$value = with(new Foo)-&gt;doWork();
</code></pre>
</body>
</html>